<?php namespace App\Http\Controllers\Index;

use App\Http\Controllers\Controller;
use App\Models\Item;
use App\Models\Area;
use App\Models\Catalog;
use Illuminate\Http\Request;

class HomeController extends Controller
{

    public function index(Request $request)
    {
        $provinces = Area::where(['p_id' => 0, 'level' => 1])->get();
        return view('index.home.index', [
            'provinces' => $provinces,
            'cities' => Area::where(['p_id' => $provinces->first()->id, 'level' => 2])->get(),
            'p_catalogs' => Catalog::where(['p_id' => 0, 'level' => 1])->get(),
            'lostItems' => Item::where('type', 'lost')->orderby('id', 'desc')->take(10)->get(),
            'findItems' => Item::where('type', 'find')->orderby('id', 'desc')->take(10)->get(),
            'lostPeoples' => Item::where(['type' => 'lost', 'p_catalog_id' => 3])->orderby('id', 'desc')->take(10)->get()
        ]);
    }

}
